import { HTTP } from "@/tools";
import { ApplicationClientType, ApplicationUseType, BUSNISSTYPE, MENUTYPE, OPENTYPE, StandardResponse } from "./standard";

export interface GetTokenParams {
  uuid: string,
  account: string,
  password: string,
  captcha: string,
}

export async function getToken(params: GetTokenParams) {
  return HTTP.post<StandardResponse<{ token: string }>>('/login', params)
}


export interface LoginUserAppInfoItem {
  active: boolean,
  code: string,
  name: string
  userClient: ApplicationClientType
}
export interface LoginUserRuleInfoItem {
  id: string,
  code: string,
  name: string,
  dataScopeType: number
}
export interface LoginUserMenuMetaInfo {
  icon: string,
  link: string,
  show: boolean,
  target: string,
  title: string
}
export interface LoginUserMenuInfo {
  component: string,
  hidden: boolean,
  id: number,
  meta: LoginUserMenuMetaInfo,
  name: string,
  path: string,
  pid: number,
  redirect: string
}
export interface LoginUserEmpInfo {
  extOrgPos: any[],
  jobNum: string,
  orgId: number,
  orgName: string,
  positions: any[]
}
export interface UserInfoResult {
  account: string,
  additionalInfo: any,
  adminType: 2 | 1,
  apps: LoginUserAppInfoItem[],
  avatar: string,
  birthday: string,
  dataOrgScopes?: string[],
  dataScopes?: string[],
  email: string,
  id: number,
  lastLoginAddress: string,
  lastLoginBrowser: string,
  lastLoginIp: string,
  lastLoginOs: string,
  lastLoginTime: string,
  loginEmpInfo: Partial<LoginUserEmpInfo>,
  menus: LoginUserMenuInfo[],
  name: string,
  nickName: string,
  permissions: string[],
  phone: string,
  roles: LoginUserRuleInfoItem[],
  sex: number,
  singleScope: boolean,
  tel: string,
  tenants?: any,
  relevancyId: string,
  sysType: ApplicationUseType,
}

export interface LoginFormInfo {

  account: string,
  captcha: string,
  password: string,
  uuid: string

}
export async function HandleLogin(params: LoginFormInfo) {
  return HTTP.post<any, { token: string }>('/login', params)
}
export async function getLoginUserInfo() {
  return HTTP.post<StandardResponse<UserInfoResult>>('/getLoginUser')
}


export async function logout() {
  return HTTP.post('/logout')
}
